package sjtu.ist.warehouse4ws.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import sjtu.ist.warehouse4ws.model.Domainmodel;
import sjtu.ist.warehouse4ws.model.Epcunit;
import sjtu.ist.warehouse4ws.model.Epcunits;
import sjtu.ist.warehouse4ws.service.EpcUnitService;
import sjtu.ist.warehouse4ws.service.EpcunitsService;
import sjtu.ist.warehouse4ws.service.OplogService;

import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;



public class ShowEpcAction extends ActionSupport{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5605567980406358826L;
	private List<Epcunit> epcList = new ArrayList<Epcunit> ();
	private EpcUnitService epcunitService;
	private EpcunitsService epcunitsService;
	private OplogService oplogService;
	private String xmlName;
	
	public void setEpcUnitService(EpcUnitService epcunitService){
		this.epcunitService=epcunitService;
	}

	public void setEpcunitsService(EpcunitsService epcunitsService) {
		this.epcunitsService = epcunitsService;
	}

	public void setOplogService(OplogService oplogService) {
		this.oplogService = oplogService;
	}
	public String getXmlName() {
		return xmlName;
	}
	public void setXmlName(String xmlName) {
		this.xmlName = xmlName;
	}
	public void setEpcList(List<Epcunit> epcList) {
		this.epcList = epcList;
	}
	//EpcModel
	public String showEpc(){
		HttpServletRequest request = ServletActionContext.getRequest ();
		this.xmlName=request.getParameter("text");
		
		this.epcList=epcunitService.getEpcunitListById(xmlName);
		
		//插入日志记录/////////////////////////////////////////////////////
		if(epcList.size()>0){
			String epcid=epcList.get(0).getEpcId();
			Epcunits epc=epcunitsService.getEpc(xmlName);
			
			ActionContext actionContext = ActionContext.getContext();
			Map session = actionContext.getSession();
			String user_id = session.get("user_id").toString();
			oplogService.recordLog(user_id, epc.getFileId(), "查看EPC模型", "readop");
		}		
		//////////////////////////////////////////////////////////////////////
		
		return SUCCESS;
		}
	@JSON(name = "totalEpc")	
	public int getTotalEpc() {
		return this.epcList.size();
	}
    
	@JSON(name ="Epc")	
	public List<Epcunit> getEpcList() {
		return this.epcList;
	}

}
